global r4data "/.../data"
global output "/.../output/_10ygroup"
set more off
set linesize 255

*----------------------------------------------------------------------------------------------------
* Author: Dhiren Patki
*
* This program re-estimates the analysis from 07a but does so on the sample of cohorts
* where 10 years of post-event data are observed. The structure of the program is as follows:
* a) estimates propensity scores 
* b) estimates regression models 
*----------------------------------------------------------------------------------------------------

*Read in stacked cohort cells 
use "$r4data/wkerpanel_m", clear

*keep cohorts where 10 years of post-event data are observed
keep if inlist(group,2001,2002,2003,2004)

*Cell earnings are missing if all workers retire/NILF; replace with 0
replace total_earn = 0 if total_earn==.

*Age splits
local a1=25
local a2=39
local a3=40
local a4=49
local a5=50
local a6=55
local a7=56
local a8=64
local a9=65
local a10=70

*----------------------------------------------------------------------------------------------------
*		Estimate propensity scores/define common support comparison groups
*----------------------------------------------------------------------------------------------------


*No restriction on earnings (R, LFP outcome samples)

forvalues a = 1/7{

	if `a' == 1 { //25-39
	    local amin = `a1'
	    local amax = `a2'
	}
	else if `a' == 2 { //40-49
	    local amin = `a3'
	    local amax = `a4'
	}
	else if `a' == 3 { //50-55
	    local amin = `a5'
	    local amax = `a6'	
	}
	else if `a' == 4 { //50-54
	    local amin = `a5'
	    local amax = `a6'-1	
	}
	else if `a' == 5 { //56-64
	    local amin = `a7'
	    local amax = `a8'	
	}
	else if `a' == 6 { //65-70
	    local amin = `a9'
	    local amax = `a10'	
	}
	else if `a' == 7 { //25-70
	    local amin = `a1'
	    local amax = `a10'	
	}

	**Start pscore estimation step
	preserve
		local x1 "group source_at_cm5 sex_enc age_at_c no_hsd hsd some_coll coll_plus white black asian otrace hispanic av_tearn_pre log_earnpc5 tenure_cm5 firmage_cm5 av_erngwth_pre"
		local x2 "total_earn logearn R lfp ee_sep liab_active_partcp incr_liab_partcp log_liab_active_p log_incr_liab_active_p"
		local x3 "log_size lbd_emp frac_lte45 frac_46_50 frac_51_55 frac_56_60 frac_61_65 frac_66_70 frac_gte71"
		local x "`x1' `x2' `x3'"

		keep idvar `x' numpik plan_r_age treat_flag enc_first_firmid k 
		keep if inrange(age_at_c,`amin',`amax')
		keep if k<0
		keep if tenure_cm5>=2
		gen otrace2 = asian + otrace
		drop asian otrace
		rename otrace2 otrace
		
		*Coarsen plan_r_age
		bysort idvar: egen plan_r_age_av = mean(plan_r_age)
		drop plan_r_age
		replace k = k*-1

		*Redacted: drop cases with outlying plan retirement ages 

		reshape wide `x2' `x3', i(idvar) j(k)
		rename source_at_cm5 state
		rename tenure_cm5 tenure

		local x1 "i.group i.state i.sex_enc##i.age_at_c i.tenure"
		local x2 "hsd some_coll coll_plus white black otrace hispanic"
		local x3 "plan_r_age_av log_earnpc5 av_erngwth_pre total_earn* R* lfp* ee_sep* log_liab_active_p* log_incr_liab_active_p*"
		local x4 "log_size* frac_lte45* frac_46_50* frac_51_55* frac_56_60* frac_61_65* frac_66_70*"
		local x "`x1' `x2' `x3' `x4'"
		set matsize 1000

		*Estimate pscore and generate match sample indicators
		logit treat_flag `x' 
		predict pscore, pr
		psmatch2 treat_flag, pscore(pscore) common 
		*Estimate weights
		gen temp = pscore/(1-pscore) if _support==1 //p(x)/1-p(x)
		sum temp if treat_flag==0 //preferred adjustment for ATT
		gen rho_hat = r(mean)
		gen invpwt_c = temp/rho_hat if _support==1 //ATT reweighting variable
		gen invpwt_c_size = .
		replace invpwt_c_size = numpik if treat_flag==1 & _support==1 //adjust for cell size
		replace invpwt_c_size = numpik*invpwt_c if treat_flag==0 & _support==1 //adjust for cell size

		*Check overlap condition (pscore<1 in comparison group)
		tabstat pscore if _support==1 & treat_flag==0, by(treat_flag) stats(N min max mean p50)
		tabstat pscore if _support==1 & treat_flag==1, by(treat_flag) stats(N min max mean p50)

		*Re-bin time varying variables into [c-5,c-1] averages for cells within common support
		local x1 "total_earn R lfp ee_sep liab_active_partcp incr_liab_partcp lbd_emp"
		local x2 "frac_lte45 frac_46_50 frac_51_55 frac_56_60 frac_61_65 frac_66_70 frac_gte71"
		local vars "`x1' `x2'"
		foreach v of local vars {
		      egen `v'_av = rowmean(`v'1 `v'2 `v'3 `v'4 `v'5) if _support==/*redacted*/
		}
		
		forvalues v = 1/5{
		  gen log_total_earn`v' = log(total_earn`v')
		}

		local x3 "log_liab_active_p log_incr_liab_active_p log_size log_total_earn"
		foreach v of local x3{
		      egen `v'_av = rowmean(`v'1 `v'2 `v'3 `v'4 `v'5) if _support==/*redacted*/
		}

		rename invpwt_c_size invpwt_c_size`a'
		keep idvar invpwt_c_size`a'
		save $r4data/pscore_samp`a'_10ygroup, replace
	restore
	**end pscore estimation step
}

*Positive earnings sample (logearn, total_earn, ee_sep outcome samples)
forvalues a = 1/7{

	if `a' == 1 { //25-39
	    local amin = `a1'
	    local amax = `a2'
	}
	else if `a' == 2 { //40-49
	    local amin = `a3'
	    local amax = `a4'
	}
	else if `a' == 3 { //50-55
	    local amin = `a5'
	    local amax = `a6'	
	}
	else if `a' == 4 { //50-55
	    local amin = `a5'
	    local amax = `a6'-1	
	}
	else if `a' == 5 { //56-64
	    local amin = `a7'
	    local amax = `a8'	
	}
	else if `a' == 6 { //65-70
	    local amin = `a9'
	    local amax = `a10'	
	}
	else if `a' == 7 { //25-70
	    local amin = `a1'
	    local amax = `a10'	
	}

	**Start pscore estimation step
	preserve
		local x1 "group source_at_cm5 sex_enc age_at_c no_hsd hsd some_coll coll_plus white black asian otrace hispanic av_tearn_pre log_earnpc5 tenure_cm5 firmage_cm5 av_erngwth_pre"
		local x2 "total_earn logearn R lfp ee_sep liab_active_partcp incr_liab_partcp log_liab_active_p log_incr_liab_active_p"
		local x3 "log_size lbd_emp frac_lte45 frac_46_50 frac_51_55 frac_56_60 frac_61_65 frac_66_70 frac_gte71"
		local x "`x1' `x2' `x3'"

		keep idvar `x' numpik plan_r_age treat_flag enc_first_firmid k 
		keep if inrange(age_at_c,`amin',`amax')
		keep if k<0
		keep if tenure_cm5>=2
		keep if total_earn>0 //positive earnings restriction imposed here!
		gen otrace2 = asian + otrace
		drop asian otrace
		rename otrace2 otrace
		
		*Coarsen plan_r_age
		bysort idvar: egen plan_r_age_av = mean(plan_r_age)
		drop plan_r_age

		replace k = k*-1

		*Redacted: drop cases with outlying plan retirement ages 

		reshape wide `x2' `x3', i(idvar) j(k)
		rename source_at_cm5 state
		rename tenure_cm5 tenure

		local x1 "i.group i.state i.sex_enc##i.age_at_c i.tenure"
		local x2 "hsd some_coll coll_plus white black otrace hispanic"
		local x3 "plan_r_age_av log_earnpc5 av_erngwth_pre total_earn* R* lfp* ee_sep* log_liab_active_p* log_incr_liab_active_p*"
		local x4 "log_size* frac_lte45* frac_46_50* frac_51_55* frac_56_60* frac_61_65* frac_66_70*"
		local x "`x1' `x2' `x3' `x4'"
		set matsize 1000

		*Estimate pscore and generate match sample indicators
		logit treat_flag `x' 
		predict pscore, pr
		psmatch2 treat_flag, pscore(pscore) common 
		*Estimate weights
		gen temp = pscore/(1-pscore) if _support==1 //p(x)/1-p(x)
		sum temp if treat_flag==0 //preferred adjustment for ATT
		gen rho_hat = r(mean)
		gen invpwt_c = temp/rho_hat if _support==1 //ATT reweighting variable
		gen invpwt_c_size = .
		replace invpwt_c_size = numpik if treat_flag==1 & _support==1 //adjust for cell size
		replace invpwt_c_size = numpik*invpwt_c if treat_flag==0 & _support==1 //adjust for cell size

		*Check overlap condition (pscore<1 in comparison group)
		tabstat pscore if _support==1 & treat_flag==0, by(treat_flag) stats(N min max mean p50)
		tabstat pscore if _support==1 & treat_flag==1, by(treat_flag) stats(N min max mean p50)

		*Re-bin time varying variables into [c-5,c-1] averages for cells within common support
		local x1 "total_earn R lfp ee_sep liab_active_partcp incr_liab_partcp lbd_emp"
		local x2 "frac_lte45 frac_46_50 frac_51_55 frac_56_60 frac_61_65 frac_66_70 frac_gte71"
		local vars "`x1' `x2'"
		foreach v of local vars {
		      egen `v'_av = rowmean(`v'1 `v'2 `v'3 `v'4 `v'5) if _support==/*redacted*/
		}
		
		forvalues v = 1/5{
		  gen log_total_earn`v' = log(total_earn`v')
		}

		local x3 "log_liab_active_p log_incr_liab_active_p log_size log_total_earn"
		foreach v of local x3{
		      egen `v'_av = rowmean(`v'1 `v'2 `v'3 `v'4 `v'5) if _support==/*redacted*/
		}

		rename invpwt_c_size invpwt_erc_size`a'
		keep idvar invpwt_erc_size`a'
		save $r4data/pscore_ersamp`a'_10ygroup, replace
	restore
	**end pscore estimation step
}


*Merge pscores onto main file
forvalues a = 1/7{
  merge m:1 idvar using $r4data/pscore_samp`a'_10ygroup
  rename _merge merge_age`a'
}

forvalues a = 1/7{
  merge m:1 idvar using $r4data/pscore_ersamp`a'_10ygroup
  rename _merge merge_age_er`a'
}

*----------------------------------------------------------------------------------------------------
*			Retirement, LFP, earnings, and switching outcomes
*----------------------------------------------------------------------------------------------------

*Covariates
gen age2 = age^2
gen D_m5m3 = (D_m5==1 | D_m4==1 | D_m3==1)
gen D_m2m1 = (D_m2==1 | D_m1==1)
gen D_p1p2 = (D_p1==1 | D_p2==1)
gen D_p3p4 = (D_p3==1 | D_p4==1)
gen D_p5p6 = (D_p5==1 | D_p6==1)
gen D_p7p8 = (D_p7==1 | D_p8==1)
gen D_p9p10 = (D_p9==1 | D_p10==1)
gen D_p11p12 = (D_p11==1 | D_p12==1)
local x1 "D_m5 D_m4 D_m3 D_m2 D_m1 D_0 D_p1 D_p2 D_p3 D_p4 D_p5 D_p6 D_p7 D_p8 D_p9 D_p10 D_p11 D_p12 D_p13"
local x2 "age age2 i.sex_enc i.sex_enc#c.age i.sex_enc#c.age2 hsd some_coll coll_plus white black asian hispanic log_earnpc5 av_erngwth_pre"
local x "`x1' `x2'"
local x3 "D_m5m3 D_m2m1 D_0 D_p1p2 D_p3p4 D_p5p6 D_p7p8 D_p9p10 D_p11p12 D_p13"
local xcons "`x3' `x2'"
local fe "group#k source_at_cm5 tenure_cm5 enc_first_firmid"

*Depvars
local depvars1 "lfp R"
local depvars2 "logearn ee_sep" //these variables require >0 earnings


foreach y of local depvars1{
	
	**********
	* 25-39
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a2') [aw=invpwt_c_size1], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age1 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age1 [aw=invpwt_c_size1], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (cell weight))
	
	**********
	* 40-49
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a3',`a4') [aw=invpwt_c_size2], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age2 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age2 [aw=invpwt_c_size2], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (cell weight))		

	**********
	* 50-55
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`a6') [aw=invpwt_c_size3], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age3 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age3 [aw=invpwt_c_size3], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-55 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-55 (cell weight))
	
	**********
	* 50-54
	**********
	local b = `a6'-1
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`b') [aw=invpwt_c_size4], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age4 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age4 [aw=invpwt_c_size4], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (cell weight))
	
	**********
	* 56-64
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a7',`a8') [aw=invpwt_c_size5], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age5 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age5 [aw=invpwt_c_size5], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (cell weight))

	**********
	* 65-70
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a9',`a10') [aw=invpwt_c_size6], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age6 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age6 [aw=invpwt_c_size6], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (cell weight))

	**********
	* 25-70
	**********	
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a10') [aw=invpwt_c_size7], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (IPW))
	if "`y'"== "lfp"{
	    gen pw_samp_age7 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age7 [aw=invpwt_c_size7], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_samp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_samp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (cell weight))
	
}


*Depvars (log earnings and employer switching)

foreach y of local depvars2{

	if "`y'" == "logearn"{ 
	
	**********
	* 25-39
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a2') [aw=invpwt_erc_size1], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age1 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age1 [aw=invpwt_erc_size1], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (cell weight))
	
	**********
	* 40-49
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a3',`a4') [aw=invpwt_erc_size2], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age2 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age2 [aw=invpwt_erc_size2], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (cell weight))		

	**********
	* 50-55
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`a6') [aw=invpwt_erc_size3], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age3 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age3 [aw=invpwt_erc_size3], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-55 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (cell weight))
	
	**********
	* 50-54
	**********
	local b = `a6'-1
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`b') [aw=invpwt_erc_size4], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age4 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age4 [aw=invpwt_erc_size4], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (cell weight))
	
	**********
	* 56-64
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a7',`a8') [aw=invpwt_erc_size5], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age5 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age5 [aw=invpwt_erc_size5], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (cell weight))

	**********
	* 65-70
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a9',`a10') [aw=invpwt_erc_size6], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age6 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age6 [aw=invpwt_erc_size6], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (cell weight))

	**********
	* 25-70
	**********	
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a10') [aw=invpwt_erc_size7], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (IPW))
	if "`y'"== "logearn"{
	    gen pw_ersamp_age7 = e(sample)
	}

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age7 [aw=invpwt_erc_size7], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (cell weight))

	}

	else if "`y'"=="ee_sep"{

	**********
	* 25-39
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a2') & pw_ersamp_age1 [aw=invpwt_erc_size1], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age1 [aw=invpwt_erc_size1], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, replace auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-39 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age1 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-39 (cell weight))
	
	**********
	* 40-49
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a3',`a4') & pw_ersamp_age2 [aw=invpwt_erc_size2], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age2 [aw=invpwt_erc_size2], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(40-49 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age2 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (cell weight))		

	**********
	* 50-55
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`a6') & pw_ersamp_age3 [aw=invpwt_erc_size3], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age3 [aw=invpwt_erc_size3], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-55 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-55 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age3 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(40-49 (cell weight))
	
	**********
	* 50-54
	**********
	local b = `a6'-1
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a5',`b') & pw_ersamp_age4 [aw=invpwt_erc_size4], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age4 [aw=invpwt_erc_size4], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(50-54 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age4 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(50-54 (cell weight))
	
	**********
	* 56-64
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a7',`a8') & pw_ersamp_age5 [aw=invpwt_erc_size5], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age5 [aw=invpwt_erc_size5], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(56-64 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age5 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(56-64 (cell weight))

	**********
	* 65-70
	**********
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a9',`a10') & pw_ersamp_age6 [aw=invpwt_erc_size6], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age6 [aw=invpwt_erc_size6], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(65-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age6 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(65-70 (cell weight))

	**********
	* 25-70
	**********	
	*p-score weighted
	reghdfe `y' `x' if inrange(age_at_c,`a1',`a10') & pw_ersamp_age7 [aw=invpwt_erc_size7], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (IPW))

	*p-score weighted, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age7 [aw=invpwt_erc_size7], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (IPW))

	*no re-weighting
	reghdfe `y' `x' if pw_ersamp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	test D_m5=D_m4=D_m3=D_m2=D_m1=0
	local F = r(F)
	local p = r(p)
	outreg2 `x1' using $output/`y'_effects_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust), F test, `F', Prob>F, `p') ctitle(25-70 (cell weight))

	*no re-weighting, consolidating coefficients
	reghdfe `y' `xcons' if pw_ersamp_age7 [aw=numpik], a(`fe') vce(cluster enc_first_firmid)
	outreg2 `x3' using $output/`y'_effects_consol_10ygroup, auto(4) ///
	addtext(Firm FE, Yes, Group-period FE, Yes, State FE, Yes, c-5 Tenure FE, Yes) ///
	addstat(Number of firms, e(N_clust)) ctitle(25-70 (cell weight))

	}
		
}

*----------------------------------------------------------------------------------------------------
*Save file for disclosure statistics
*----------------------------------------------------------------------------------------------------


preserve

	keep group firmid year sex_enc age_at_c source_at_cm5 tenure_cm5 idvar enc_first_firmid D* treat_flag ///
	pw_samp_age* pw_ersamp_age* lbd_emp lbd_pay numpik invpwt_c_size* invpwt_erc_size*
	save $r4data/analysis_sampflag_10ygroup, replace

restore






